package com.zhuiwei.springbootamqp.service;

import com.zhuiwei.springbootamqp.bean.Book;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

/**
 * 监听队列
 * @author zhuiwei
 * @version 2019/05/24
 */
@Service
public class BookService {

    /**
     * 监听消息队列
     * @param book 自定义Bean对象
     */
    @RabbitListener(queues = "so.news")
    public void receive(Book book){
        System.out.println("消息队列中的消息："+book);
        System.out.println("数据："+book.getName()+" "+book.getAuthor());

    }

    /**
     * 获取Message消息
     * @param message
     */
    @RabbitListener(queues = "so")
    public void receive2(Message message){
        System.out.println(message.getBody());
        System.out.println(message.getMessageProperties());
    }

}
